package com.hj.storage.controller;

import com.hj.response.resp.RestfulResult;
import com.hj.storage.domain.req.ThreeReq;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.web.bind.annotation.*;

/**
 * @author hj
 * @Date 2023/5/19
 * @Description:
 */
@RestController
@RequestMapping("/file/random")
@Tag(name = "随机测试咯")
public class RandomController {

    /**
     * tip: Name for argument of type [java.lang.String] not specified,
     * and parameter name information not found in class file either.
     * 报这个错的时候 就加个 @RequestParam属性吧.. 这只是测试.实际开发中
     * 建议使用 @RequestBody post请求 来接收参数. 统一 json格式 爽歪歪
     *
     * @param name name
     * @return String
     */
    @PostMapping("one")
    @Operation(summary = "string")
    public String one(String name) {
        String one = "one-" + name;
        System.out.println(one);
        return one;
    }

    /**
     * tip: 这儿直接返回 RestfulResult对象, feign调用方就能直接用这个接收,
     * 否则通过全局返回处理,返回的就是一个json对象,feign调用方需要做转换
     *
     * @param name name
     * @return RestfulResult<String>
     */
    @GetMapping("two")
    @Operation(summary = "string")
    public RestfulResult<String> two(String name) {
        String two = "two-" + name;
        System.out.println(two);
        RestfulResult<String> result = new RestfulResult<>();
        result.setCode(200);
        result.setData(two);
        result.setMsg("success");
        return result;
    }

    /**
     * tip: @RequestBody 必须加.否则对方调用 加不加这个注解这边都接收不到参数
     *
     * @param req ThreeReq
     * @return String
     */
    @PostMapping("three")
    @Operation(summary = "string")
    public String three(@RequestBody ThreeReq req) {
        String three = "three-" + req.getName();
        System.out.println(three);
        return three;
    }

    @PostMapping("four")
    @Operation(summary = "string")
    public String four(@RequestBody ThreeReq req) {
        String four = "four-" + req.getName();
        System.out.println(four);
        return four;
    }


}
